#20.有效的括号

def isValid(s):
    """
    :type s: str
    :rtype: bool
    """
    dic = {')': '(', ']': '[', '}': '{'}
    stack = []
    for i in s:
        if stack and i in dic:
            if stack[-1] == dic[i]:
                stack.pop()
            else:
                return False
        else:
            stack.append(i)
    return not stack

print(isValid('()'))
print(isValid('()[]{}'))